//
// Created by ttao on 2022/8/4.
//
#ifndef TCPSERVER_CONTAINER_H
#define TCPSERVER_CONTAINER_H
/* ================ start of Stack.c ================ */

typedef struct {
    char **head;            // 栈首地址
    long point;         // 栈顶计数器
    long maxlen;        // 栈长度
} stack;

static inline stack *initStack(stack *s, char **head, long MAXSIZE)
{
    s->head = head;
    s->maxlen = MAXSIZE;
    s->point = 0;
}

void stack_clear(stack *s);
int push(stack *s, void *node);
void *pop(stack *s);
int isempty(stack *s);
/* ================ end of Stack.c ================ */


/* ================ end of Lists.c ================ */
enum InsertType{
    BEFORE,
    AFTER,
};
struct Table{
    struct Table *prev;
    struct Table *next;
    char *value;
} ;
struct LinkList{
    struct Table* head;
    struct Table* tail;
    struct Table* cursor;   //游标
    long size;
};
typedef struct Table table_t;
typedef struct LinkList linklist_t;

void initLinkList(linklist_t *list);
void addlinklisttable(linklist_t *list, void *val);          // 追加数据 后面插入
void inserttable(linklist_t *list, void *val, table_t *itb, enum InsertType type);
void linklisteachinit(linklist_t *list);// 元素遍历前一定要调用
int hasnext(linklist_t *list);
table_t *getTb(linklist_t *list);
int destrylinklist(linklist_t *list, table_t *tb);                    // 销毁元素
/* ================ start of Lists.c ================ */

/* ================ start of Queue.c ================ */
struct Queue{
    struct Table *head;
    struct Table *tail;
    int size;
    int maxsize;
};
struct Queue *initQueue(struct Queue *queue, int MAXSIZE);
struct Queue *add(struct Queue *queue, void *table);
void *get(struct Queue *queue);
void queueeach(struct Queue *queue, void (*queueeachcallbak)(void *val));
/* ================ end of Queue.c ================ */
#endif //TCPSERVER_CONTAINER_H
